
// import bear from '../utils/bear'
let func = require("../utils/functions")
let bear  = require("../utils/bear")
let mongodb = require("../utils/db.mongo")
//let mongodb = new dbMongo()


// const config = require('../config/config.js')
// const Monk   = require('monk');
// const mongodb = new Monk( '192.168.10.15/chat' )


class test{
    constructor() {
      console.log('aaaa constructor' )
    }
    index(ctx, next){
      console.log('index/index');
    }

    

}

const fn_index = async (ctx, next) => {
    //let test = new bear()
    //test.aaa();
    indexs.index();
    //const students = mongodb.get('apply');
    let st = await mongodb.findAll('apply');
    console.log(st)
    ctx.response.type = 'application/json';
    ctx.body = st;
    //let index = new index()
    //ctx.response.body = '<h1>Hello world</h1>'
}

const fn_signin = async (ctx, next) => {
    var ct = JSON.stringify(ctx);
    //console.log(mongo.get('apply'))
    await ctx.render('index', {
      title: 'signin',
      names: ['Han Meimei', 'Sun Lili', 'Heymans', 'allen']
    });
}



let ScrollLoad = function () {    
    let _range = 80;             //距下边界长度/单位px
    let _loaded = false;            //是否所有数据已加载完
    let _pageIndex = 1;

    let _test_f = function(){
      return 'aaaa';
    }   
    //其他代码
    //...略
    console.log('ScrollLoad')
    return function () {

        this.Range = _range;        
        this.Loaded = _loaded;
        this.PageIndex = _pageIndex;

        this.test_f = function(){
          return 'aaaa';
        }   
    }
}();

function testaaa(){
    console.log('testaaa')
}

const demo_test = async (ctx, next) => {
    var a = new ScrollLoad();
    console.info(a.test_f());

    return false;
    console.log(mongodb.dbState())
    let dbState
    await mongodb.dbState().then((res)=>{
        console.log(res)
        dbState = res
        
    });
    if(dbState != 'open') return ctx.body = func.toJson('',200, '链接失败')

    await mongodb.findLimitCount('apply').then((res)=>{
        count = res
    });
    return ctx.body = func.toJson(count,200, 'ok')

}

module.exports = {
    'GET /test/index': fn_index,
    'GET /demo_test': demo_test,
    'GET /test_f': new test().index
}

